package com.source.codemap;

import static com.source.codemap.file.LoopFileReadCodeUtil.getJavaFilePaths;

import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.source.auto.utils.LogUtil;
import com.source.codemap.analyze.ClassInfoAnalyzer;
import com.source.codemap.model.ClassModel;
import com.source.codemap.model.MethodModel;
import java.util.List;
import java.util.Map;
import java.util.Optional;


/**
 * @author wangchangjie
 * @date 2025/1/14 17:04
 */

public class StartAnalyze {


    public static Map<String/*全类名*/, ClassModel> classInfoMap;

    public static Map<String/*方法全路径名称*/, MethodModel> methodInfoMap;



    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        String folderPath = "E:\\data\\javaLearn\\analyze\\src\\main\\java\\com\\source\\codemap\\resource";
        List<String> javaFilePaths = getJavaFilePaths(folderPath);

        for (String filePath : javaFilePaths) {
            LogUtil.printf("\nProcessing file: {}", filePath);
            Optional<CompilationUnit> analyze = ClassInfoAnalyzer.analyze(filePath);
            if (analyze.isPresent()) {
                CompilationUnit unit = analyze.get();
                // 获取类的全路径
                unit.findAll(ClassOrInterfaceDeclaration.class).forEach(cls -> {
                    cls.getFullyQualifiedName().ifPresent(fullPath -> {
                        LogUtil.printf("Class: {}", fullPath);

                        // 获取类中所有方法的全路径名称
                        cls.getMethods().forEach(method -> {
                            String methodFullPath = fullPath + "#" + method.getNameAsString();
                            LogUtil.printf("    Method: {}", methodFullPath);
                        });
                    });
                });
            }
        }
        LogUtil.printf("==========================代码分析提取结束==========================");
        long elapsedTime = System.currentTimeMillis() - start;
        LogUtil.printf("总耗时：{}ms", elapsedTime);
    }

}
